
import matplotlib.pyplot as plt
import numpy as np
import matplotlib

# 获取系统的字体库列表
def fun1():
    a = sorted([f.name for f in matplotlib.font_manager.fontManager.ttflist])

    for i in a:
        print(i)

# 设置中文为系统中的字体
def fun2():
    plt.rcParams['font.family'] = 'Microsoft YaHei'

    # 创建数据
    x = [1, 2, 3, 4, 5]
    y = [2, 4, 6, 8, 10]

    # 绘制折线图
    plt.plot(x, y, marker='o')

    # 添加标题和标签
    plt.title('折线图示例')
    plt.xlabel('X轴')
    plt.ylabel('Y轴')

    plt.show()

# 设置中文为下载的字体
def fun3():
    zhfont = matplotlib.font_manager.FontProperties(fname="../SourceHanSansSC-Bold.otf")

    x = np.arange(1, 11)
    y = 2 * x + 5

    plt.title("测试", fontproperties=zhfont)

    plt.xlabel('X轴', fontproperties=zhfont)
    plt.ylabel('Y轴', fontproperties=zhfont)
    plt.plot(x, y)
    plt.show()


if __name__ == '__main__':
    fun3()